#include <stdio.h>
#include <string.h>

const size_t CAPACITY = 1024;
// WARNING: This is not a thread-safe store.
// If API clients access it concurrently, then there could be issues.
char store[1024];

void clear_store() {
    memset(store, '\0', CAPACITY);
}

void set_err(const char* message) {
    clear_store();
    size_t length = strlen(message);
    memcpy(store, message, length);
}

int get_err(char* message, size_t size) {
    memcpy(message, store, size);
    message[size] = '\0';

    return strlen(message);
}
